<?php
/**
 * 微博后台管理项目 媒体表数据层

 */
define("CACHE_MBLOG_COUNT_RT_TOP","tuijian_daren_");
class db_tuijian_daren extends db_base
{
	var $table_name  ="tuijian_daren";
	
	
	
	function get_item_by_id($id)
	{
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-get_item_by_id-{$id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = "id =$id and status = 1  ";
			$content = $this->get_alllist($this->table_name,1,1, "", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content[0];
	}
	
	
	/**
	 * 根据D_ID取数据
	 * @param $d_id
	 */
	function get_list_by_order($p=1,$pcount=10,$max_id="")
	{
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-get_list_by_order-{$max_id}-{$p}-{$count}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$where = "id <= $max_id and status =1  ";
			$content = $this->get_alllist($this->table_name,$p,$count, " id desc", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	function get_top_list_by_order($p=1,$pcount=10,$max_id="",$site_id="")
	{
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-get_list_by_order-{$max_id}-{$p}-{$count}-{$site_id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			if($site_id)
			{
				$where = "id <= $max_id and status =1  and site_id = $site_id";
			}
			else
			{
				$where = "id <= $max_id and status =1  ";
			}
			
			$content = $this->get_alllist($this->table_name,$p,$pcount, " id desc", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	function get_count_by_max_id($max_id="")
	{
		$key = CACHE_MBLOG_COUNT_RT_TOP . "-get_count_by_max_id-{$max_id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$where = "id <= $max_id and status =1  ";
			$content = $this->get_listcount($this->table_name,$where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	function admin_insert_tuijian_daren($uid,$order,$detail_info,$admin_uid,$site_id)
	{
		$ary["uid"] = $uid;
		$ary["site_id"] = $site_id;
		$ary["order"] = $order;
		$ary["detail_info"] = $detail_info;
		$ary["status"] = 1;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
	 
		$ary["create_uid"] = $admin_uid;
		$res = $this->insert($this->table_name,$ary,"",true);
		
		return $res;
		
	}
	
	function admin_get_item_by_id($id)
	{
		$where = "id =$id and status = 1  ";
		$content = $this->get_alllist($this->table_name,1,1, "", $where);

		return $content[0];
	}
	
	function admin_update_by_id($id,$status="",$uid="",$order="",$detail_info,$admin_uid,$site_id)
	{
		$where = "id = $id";
		
		if(strlen($status)>0)$ary["status"] = $status;
		if(strlen($uid)>0)$ary["uid"] = $uid;
		if(strlen($order)>0)$ary["order"] = $order;
		if(strlen($detail_info)>0)$ary["detail_info"] = $detail_info;
		if(strlen($site_id)>0)$ary["site_id"] = $site_id;
		
		return $this->update($this->table_name,$ary,$where);
	}
	
	
	
	function admin_get_list($status,$p=1,$pcount=10,$site_id="")
	{
		
		if($site_id)$where_array[] = " site_id ={$site_id} ";
		if(strlen($status)>0)$where_array[] = " status ={$status} ";
		
			
		$where = join(" and ",	$where_array);
		
		$content = $this->get_alllist($this->table_name,$p,$count, " `create_time` desc", $where);
	

		return $content;
	}
	function admin_get_id_list($status,$p=1,$pcount=10)
	{
		
	
		if(strlen($status)>0)$where_array[] = " status ={$status} ";
		
			
		$where = join(" and ",	$where_array);
		
		$content = $this->get_alllist($this->table_name,$p,$count, " `create_time` desc", $where,"","uid");
	

		return $content;
	}
	
	
	
	function admin_get_count($status,$site_id="")
	{
		if($site_id)$where_array[] = " site_id ={$site_id} ";
		if(strlen($status)>0)$where_array[] = " status ={$status} ";
		
			
		$where = join(" and ",	$where_array);
		
		$content = $this->get_listcount($this->table_name,$where);
	

		return $content;
	}
	
	
	
	function cron_insert_tuijian_daren($uid,$order,$detail_info)
	{
		$ary["uid"] = $uid;
		$ary["order"] = $order;
		$ary["detail_info"] = $detail_info;
		$ary["status"] = 1;
		$ary["is_tuijian"] = 1;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
	
		$res = $this->insert($this->table_name,$ary,"",true);
		
		return $res;
		
	}
	
	
	function cron_del_tuijian_daren()
	{
		$ary["order"] = "100";
		$where = "is_tuijian = 1";
		$res = $this->update($this->table_name,$ary,$where);
		return $res;
		
	}
}
